var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var node_dir = path.join(__dirname, './node_modules/');

// 文件入口
var entry = {
    index: './src/index.js',
    index2: './src/index2.js'
};

// 文件输出
var output = {
    path: 'app/',
    filename: '[name].js',
    publicPath: "http://127.0.0.1:8080/"
};

// 编辑器
var loaders = {
    loaders: [{
        test: /\.css$/,
        loader: ExtractTextPlugin.extract('style', 'css')
    }, {
        test: /\.png$/,
        loader: "file-loader?name=/[hash:8].[name].[ext]"
    }, {
        test: /\.jsx?$/,
        include: path.resolve(__dirname, 'src'),
        loaders: ['react-hot', 'babel?presets[]=react,presets[]=stage-0,presets[]=es2015,plugins[]=transform-runtime']
    }]
};

// 扩展名配置
var resolve = {
    root: path.resolve('src'),
    modulesDirectories: ['node_modules'],
    extensions: ['', '.js', '.jsx']
};

// 插件引入
var plugins = [
    new ExtractTextPlugin('[name].css'),
    new webpack.optimize.CommonsChunkPlugin({
        name: 'base',
        filename: 'static/js/base.[hash:8].js'
    }),
    new webpack.ProvidePlugin({
        React: 'react',
        ReactDOM: 'react-dom',
        $: 'jquery'
    }),
    new HtmlWebpackPlugin({
        filename: './index.html',
        template: './src/template.html',
        inject: 'body',
        minify: {
            removeComments: true,
            collapseWhitespace: false
        },
        chunks: ['base', 'index'],
        hash: false
    }),
    new HtmlWebpackPlugin({
        filename: './index2.html',
        template: './src/template.html',
        inject: 'body',
        minify: {
            removeComments: true,
            collapseWhitespace: false
        },
        chunks: ['base', 'index2'],
        hash: false
    })
];

// 输出的配置
module.exports = {
    entry: entry,
    output: output,
    module: loaders,
    resolve: resolve,
    plugins: plugins,
    externals: {
        "React": 'react',
        'ReactDOM': 'react-dom'
    }
};
